﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Init {
    import Engine.Classes.*;
    import flash.events.*;
    import Engine.Interfaces.*;
    import flash.display.*;
    import Engine.Init.*;
    import flash.text.*;
    import flash.system.*;
    import flash.net.*;

    public class FontMapperInit extends InitializationAction {

        public static const INIT_ID:String = "FontMapperInit";

        private const FONT_MAPPER_DEFINITION:String = "FontMapper";

        private var m_loader:Loader;
        private var m_url:String;

        public function FontMapperInit(){
            super(INIT_ID);
            addDependency(GlobalsInit.INIT_ID);
            addDependency(LocalizationInit.INIT_ID);
        }
        override public function execute():void{
            var _local1:String;
            this.m_url = null;
            if (GlobalEngine.localizer){
                _local1 = GlobalEngine.localizer.localeCode;
            };
            var _local2:String = GlobalEngine.stage.loaderInfo.url;
            var _local3:int = _local2.lastIndexOf("/");
            var _local4 = "";
            if (_local3){
                _local4 = _local2.substr(0, (_local3 + 1));
            };
            if (_local1 == "zh_CN"){
                this.m_url = (_local4 + "FontMapper_zh.swf");
            } else {
                if (_local1 == "ko_KR"){
                    this.m_url = (_local4 + "FontMapper_ko.swf");
                } else {
                    if (_local1 == "ja_JP"){
                        this.m_url = (_local4 + "FontMapper_ja.swf");
                    };
                };
            };
            if (this.m_url){
                this.m_loader = new Loader();
                this.m_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onLoadComplete);
                this.m_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.onLoadFailed);
                this.m_loader.load(new URLRequest(this.m_url));
            } else {
                dispatchEvent(new Event(Event.COMPLETE));
            };
        }
        private function onLoadComplete(_arg1:Event):void{
            var _local3:Class;
            var _local4:Object;
            var _local5:IFontMapper;
            var _local6:Array;
            var _local7:String;
            var _local8:Object;
            this.m_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, this.onLoadComplete);
            this.m_loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, this.onLoadFailed);
            var _local2:ApplicationDomain = _arg1.target.applicationDomain;
            if (_local2.hasDefinition(this.FONT_MAPPER_DEFINITION)){
                _local3 = (_local2.getDefinition(this.FONT_MAPPER_DEFINITION) as Class);
                if (_local3){
                    _local4 = new (_local3)();
                    _local5 = new FontMapperProxy(_local4);
                    if (GlobalEngine.localizer){
                        _local5.setLanguageCode(GlobalEngine.localizer.localeCode);
                    };
                    _local6 = _local5.getFontsToRegister();
                    for each (_local7 in _local6) {
                        _local8 = _local2.getDefinition(_local7);
                        Font.registerFont((_local8 as Class));
                    };
                    GlobalEngine.fontMapper = _local5;
                };
            };
            this.m_loader = null;
            dispatchEvent(new Event(Event.COMPLETE));
        }
        private function onLoadFailed(_arg1:Event):void{
            throw (Error((("Failed to load font mapper swf \"" + this.m_url) + "\".")));
        }

    }
}//package Init 
